from django.contrib.auth.models import User
from django.db import models


# Create your models here.
class Admin(models.Model):
    """管理员"""
    username = models.CharField(max_length=32, verbose_name='用户名')
    password = models.CharField(max_length=32, verbose_name='密码 ')

    def __str__(self):
        return self.username


class Department(models.Model):
    """部门表"""
    title = models.CharField(max_length=32, verbose_name='标题')

    def __str__(self):
        return self.title


class UserInfo(models.Model):
    """员工表"""
    name = models.CharField(max_length=16, verbose_name='姓名')
    password = models.CharField(max_length=16, verbose_name='密码')
    age = models.IntegerField(verbose_name='年龄')
    account = models.DecimalField(max_digits=10,
                                  decimal_places=2,
                                  default=0,
                                  verbose_name="账户余额")
    # create_time = models.DateTimeField(
    #                                    verbose_name='入职时间'
    #                                    )
    create_time = models.DateField(verbose_name='入职时间')
    # 外键 关联部门 约束(只能是部门表中存在的ID)
    # to="Department"与那张表关联  to_field="id" 与字段做关联
    # on_delete=models.CASCADE 级联删除 部门删除直接删除部门下员工
    # null=True, blank=True,允许为空
    depart = models.ForeignKey(to="Department",
                               to_field="id",
                               on_delete=models.CASCADE,
                               null=True,
                               blank=True,
                               verbose_name="部门")
    # django中约束性别
    gender_choices = (
        (1, "男"),
        (2, "女"),
    )
    gender = models.SmallIntegerField(verbose_name="性别",
                                      choices=gender_choices)


class PrettyNum(models.Model):
    """靓号管理"""
    level_choices = (
        (1, '一级'),
        (2, '二级'),
        (3, '三级'),
        (4, '四级'),
        (5, '五级'),
    )

    status_choices = (
        (1, '已占用'),
        (2, '未使用'),
    )

    # def __str__(self):
    #     return self.status, self.level

    mobile = models.CharField(max_length=11, verbose_name="手机号")
    price = models.IntegerField(default=0, verbose_name="价格", null=True, blank=True)
    level = models.SmallIntegerField(verbose_name="级别", choices=level_choices, default=1)
    status = models.SmallIntegerField(verbose_name="状态", choices=status_choices, default=2)


class Task(models.Model):
    """任务"""
    level_choices = (
        (1, "紧急"),
        (2, "重要"),
        (3, "临时"),
    )
    level = models.SmallIntegerField(verbose_name="级别", choices=level_choices, default=3)
    title = models.CharField(verbose_name='标题', max_length=64)
    detail = models.TextField(verbose_name='详细信息')
    user = models.ForeignKey(verbose_name='负责人', to="Admin", on_delete=models.CASCADE)
